package com.tobby.camel.camelinaction.chapter3.transform;

import java.io.File;

import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringOrderToCsvProcessorTest extends CamelSpringTestSupport {

	@Override
	protected AbstractApplicationContext createApplicationContext() {
		return new ClassPathXmlApplicationContext(
				"com/tobby/camel/camelinaction/chapter3/transform/spring-context.xml");
	}

	@Test
	public void testOrderToCsvProcessor() {
		// This is the inhouse format we want to transform to CSV
		String inhouse = "0000004444000001212320091208  1217@1478@2132";
		template.sendBodyAndHeader("direct:start", inhouse, "Date", "20160515spring");

		assertFileExists("target/orders/received/report-20160515spring.csv");

		// compare the expected file content
		File file = new File("target/orders/received/report-20160515spring.csv");
		String body = context.getTypeConverter().convertTo(String.class, file);
		assertEquals("000000444,20091208,000001212,1217,1478,2132", body);
	}

}
